﻿using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using StairsModuleAndEdit.StairsModel.CommonUnit;
using StairsModuleAndEdit.StairsModel.DataInfos;

namespace StairsModuleAndEdit.StairsModel.Kit
{
	internal class DoubleBranchAngleStairsKit : ProjectionDrawingKit
	{
		public DoubleBranchAngleStairsKit(Application app) : base(app)
		{
		}

		public bool DoubleBranchAngleStarisProfileCurves(ref DoubleBranchAngleStairs stairs, bool bDrawNoteInfo, int nBasePointIndex, bool bLRMirror, bool bTBMirror, double dRotateAngle, bool bBottom, bool bMid, bool bTop)
		{
			bool result = false;
			LineRunData leftRunData = stairs.m_LeftRunData;
			LineRunData midRunData = stairs.m_MidRunData;
			LineRunData rightRunData = stairs.m_RightRunData;
			double width = stairs.m_LandData.Width;
			double length = stairs.m_LandData.Length;
			double stairsWidth = stairs.getStairsWidth();
			bool bIsCenterUp = stairs.m_bIsCenterUp;
			double num = Geometry.LessThan(leftRunData.RunWidth, width) ? width : leftRunData.RunWidth;
			double bundingBoxHeight = num + midRunData.RunLength;
			XYZ xyz = new XYZ(leftRunData.RunLength, 0.0, 0.0);
			XYZ xyz2 = new XYZ(leftRunData.RunLength + length, 0.0, 0.0);
			XYZ zero = XYZ.Zero;
			XYZ xyz3 = new XYZ(0.0, -leftRunData.RunWidth, 0.0);
			XYZ xyz4 = new XYZ(leftRunData.RunLength, -leftRunData.RunWidth, 0.0);
			XYZ xyz5 = new XYZ(leftRunData.RunLength, 0.0, 0.0);
			XYZ xyz6 = new XYZ(leftRunData.RunLength + (length - midRunData.RunWidth) / 2.0, -width, 0.0);
			XYZ xyz7 = xyz6;
			XYZ xyz8 = new XYZ(midRunData.RunWidth, 0.0, 0.0) + xyz6;
			XYZ xyz9 = new XYZ(midRunData.RunWidth, -midRunData.RunLength, 0.0) + xyz6;
			XYZ xyz10 = new XYZ(0.0, -midRunData.RunLength, 0.0) + xyz6;
			XYZ xyz11 = new XYZ(leftRunData.RunLength + length, 0.0, 0.0);
			XYZ xyz12 = xyz11;
			XYZ xyz13 = new XYZ(rightRunData.RunLength, 0.0, 0.0) + xyz11;
			XYZ xyz14 = new XYZ(rightRunData.RunLength, -rightRunData.RunWidth, 0.0) + xyz11;
			XYZ xyz15 = new XYZ(0.0, -rightRunData.RunWidth, 0.0) + xyz11;
			stairs.m_MidRunData.PtRunBottomLeft = xyz10;
			stairs.m_MidRunData.PtRunBottomRight = xyz9;
			stairs.m_MidRunData.PtRunTopLeft = xyz7;
			stairs.m_MidRunData.PtRunTopRight = xyz8;
			stairs.m_LeftRunData.PtRunBottomLeft = zero;
			stairs.m_LeftRunData.PtRunBottomRight = xyz3;
			stairs.m_LeftRunData.PtRunTopLeft = xyz5;
			stairs.m_LeftRunData.PtRunTopRight = xyz4;
			stairs.m_RightRunData.PtRunBottomLeft = xyz14;
			stairs.m_RightRunData.PtRunBottomRight = xyz13;
			stairs.m_RightRunData.PtRunTopLeft = xyz15;
			stairs.m_RightRunData.PtRunTopRight = xyz12;
			List<XYZ> list = new List<XYZ>();
			list.Add(xyz3);
			list.Add(zero);
			list.Add(xyz13);
			list.Add(xyz14);
			list.Add(xyz9);
			list.Add(xyz10);
			stairs.m_listOutSupportPoints.Add(zero);
			stairs.m_listOutSupportPoints.Add(xyz);
			stairs.m_listOutSupportPoints.Add(xyz2);
			stairs.m_listOutSupportPoints.Add(xyz13);
			XYZ xyz16 = list[nBasePointIndex];
			base.CalulateTransform(bLRMirror, bTBMirror, dRotateAngle, stairsWidth, bundingBoxHeight, xyz16);
			stairs.m_ptPosition = Geometry.TransformPoint(xyz16, this.m_Transform);
			stairs.m_listOtherCurve.AddRange(base.DrawBasePoint(xyz16, 100.0));
			stairs.m_Transform = this.m_Transform;
			double bottomElevation;
			if (bIsCenterUp)
			{
				SingleRunCurveInfo singleRunCurveInfo = new SingleRunCurveInfo();
				singleRunCurveInfo.BottomElevation = midRunData.BottomElevation;
				base.DrawLinearRun(midRunData, xyz10, xyz9, xyz8, xyz7, ref singleRunCurveInfo, ref stairs.m_listOtherCurve, bDrawNoteInfo);
				stairs.m_listRunCurve.Add(singleRunCurveInfo);
				singleRunCurveInfo = new SingleRunCurveInfo();
				singleRunCurveInfo.BottomElevation = leftRunData.BottomElevation;
				base.DrawLinearRun(leftRunData, xyz4, xyz5, zero, xyz3, ref singleRunCurveInfo, ref stairs.m_listOtherCurve, bDrawNoteInfo);
				stairs.m_listRunCurve.Add(singleRunCurveInfo);
				singleRunCurveInfo = new SingleRunCurveInfo();
				singleRunCurveInfo.BottomElevation = rightRunData.BottomElevation;
				base.DrawLinearRun(rightRunData, xyz12, xyz15, xyz14, xyz13, ref singleRunCurveInfo, ref stairs.m_listOtherCurve, bDrawNoteInfo);
				stairs.m_listRunCurve.Add(singleRunCurveInfo);
				bottomElevation = leftRunData.BottomElevation;
			}
			else
			{
				SingleRunCurveInfo singleRunCurveInfo2 = new SingleRunCurveInfo();
				singleRunCurveInfo2.BottomElevation = midRunData.BottomElevation;
				base.DrawLinearRun(midRunData, xyz8, xyz7, xyz10, xyz9, ref singleRunCurveInfo2, ref stairs.m_listOtherCurve, bDrawNoteInfo);
				stairs.m_listRunCurve.Add(singleRunCurveInfo2);
				singleRunCurveInfo2 = new SingleRunCurveInfo();
				singleRunCurveInfo2.BottomElevation = leftRunData.BottomElevation;
				base.DrawLinearRun(leftRunData, zero, xyz3, xyz4, xyz5, ref singleRunCurveInfo2, ref stairs.m_listOtherCurve, bDrawNoteInfo);
				stairs.m_listRunCurve.Add(singleRunCurveInfo2);
				singleRunCurveInfo2 = new SingleRunCurveInfo();
				singleRunCurveInfo2.BottomElevation = rightRunData.BottomElevation;
				base.DrawLinearRun(rightRunData, xyz14, xyz13, xyz12, xyz15, ref singleRunCurveInfo2, ref stairs.m_listOtherCurve, bDrawNoteInfo);
				stairs.m_listRunCurve.Add(singleRunCurveInfo2);
				bottomElevation = midRunData.BottomElevation;
			}
			if (bDrawNoteInfo)
			{
				XYZ ptMid;
				XYZ ptLeft;
				XYZ ptRight;
				if (bIsCenterUp)
				{
					ptMid = (xyz10 + xyz9) / 2.0 - XYZ.BasisY * 1.3;
					ptLeft = (zero + xyz3) / 2.0 - XYZ.BasisX * 1.3;
					ptRight = (xyz14 + xyz13) / 2.0 + XYZ.BasisX * 1.3;
				}
				else
				{
					ptLeft = (zero + xyz3) / 2.0 - XYZ.BasisX * 1.3;
					ptRight = (xyz14 + xyz13) / 2.0 + XYZ.BasisX * 1.3;
					ptMid = (xyz10 + xyz9) / 2.0 - XYZ.BasisY * 1.3;
				}
				base.DrawUpStairsNoteInfo(ref stairs.m_listText, bIsCenterUp, ptLeft, ptMid, ptRight);
			}
			XYZ xyz17 = new XYZ(0.0, width, 0.0);
			List<CurveInfo> landCurves = new List<CurveInfo>();
			this.DrawDoubleBranchAngleStairsLanding(ref landCurves, xyz, xyz2, xyz2 - xyz17, xyz - xyz17);
			LandingCurveInfo item = new LandingCurveInfo(landCurves, bottomElevation);
			stairs.m_listLandCurve.Add(item);
			this.DrawDoubleBranchAngleStairsBeamCurves(ref stairs, bIsCenterUp, xyz, xyz2, bBottom, bMid, bTop);
			this.DrawDoubleBranchAngleStairsNoteInfo(ref stairs, zero, xyz10, xyz);
			return result;
		}

		private void DrawDoubleBranchAngleStairsBeamCurves(ref DoubleBranchAngleStairs stairs, bool bCenterStart, XYZ ptLandTopLeft, XYZ ptLandTopRight, bool bBottom, bool bMid, bool bTop)
		{
			LineRunData midRunData = stairs.m_MidRunData;
			LineRunData leftRunData = stairs.m_LeftRunData;
			if (bCenterStart)
			{
				XYZ xyz = XYZ.Zero;
				XYZ ptE = XYZ.Zero;
				if (bBottom)
				{
					XYZ xyz2 = new XYZ(0.0, stairs.m_BeamData.BeamWidth / 2.0, 0.0);
					List<CurveInfo> list = new List<CurveInfo>();
					xyz = midRunData.PtRunBottomLeft - xyz2;
					ptE = midRunData.PtRunBottomRight - xyz2;
					list.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz, ptE, xyz2));
					double bottomElevation = midRunData.BottomElevation;
					BeamCurveInfo beamCurveInfo = new BeamCurveInfo(list, bottomElevation);
					beamCurveInfo.m_Type = BeamType.BT_Bottom;
					beamCurveInfo.m_nFloorNum = 0;
					stairs.m_listBeamCurve.Add(beamCurveInfo);
				}
				if (bMid)
				{
					XYZ xyz2 = new XYZ(stairs.m_BeamData.BeamWidth / 2.0, 0.0, 0.0);
					List<CurveInfo> list2 = new List<CurveInfo>();
					xyz = ptLandTopLeft + xyz2;
					ptE = xyz - XYZ.BasisY * stairs.m_LandData.Width;
					list2.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz, ptE, null));
					xyz = ptLandTopRight - xyz2;
					ptE = xyz - XYZ.BasisY * stairs.m_LandData.Width;
					list2.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz, ptE, null));
					double bottomElevation = leftRunData.BottomElevation;
					BeamCurveInfo beamCurveInfo2 = new BeamCurveInfo(list2, bottomElevation);
					beamCurveInfo2.m_Type = BeamType.BT_Mid;
					beamCurveInfo2.m_nFloorNum = 1;
					stairs.m_listBeamCurve.Add(beamCurveInfo2);
				}
				if (bTop)
				{
					XYZ xyz2 = new XYZ(stairs.m_BeamData.BeamWidth / 2.0, 0.0, 0.0);
					List<CurveInfo> list3 = new List<CurveInfo>();
					xyz = stairs.m_LeftRunData.PtRunBottomLeft - xyz2;
					ptE = stairs.m_LeftRunData.PtRunBottomRight - xyz2;
					list3.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz, ptE, -xyz2));
					xyz = stairs.m_RightRunData.PtRunBottomLeft + xyz2;
					ptE = stairs.m_RightRunData.PtRunBottomRight + xyz2;
					list3.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz, ptE, xyz2));
					double bottomElevation = leftRunData.BottomElevation + leftRunData.RunHeight - leftRunData.TreadHeight;
					BeamCurveInfo beamCurveInfo3 = new BeamCurveInfo(list3, bottomElevation);
					beamCurveInfo3.m_Type = BeamType.BT_Top;
					beamCurveInfo3.m_nFloorNum = 2;
					stairs.m_listBeamCurve.Add(beamCurveInfo3);
					return;
				}
			}
			else
			{
				XYZ xyz3 = XYZ.Zero;
				XYZ ptE2 = XYZ.Zero;
				if (bBottom)
				{
					XYZ xyz2 = new XYZ(stairs.m_BeamData.BeamWidth / 2.0, 0.0, 0.0);
					List<CurveInfo> list4 = new List<CurveInfo>();
					xyz3 = stairs.m_LeftRunData.PtRunBottomLeft - xyz2;
					ptE2 = stairs.m_LeftRunData.PtRunBottomRight - xyz2;
					list4.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz3, ptE2, xyz2));
					xyz3 = stairs.m_RightRunData.PtRunBottomLeft + xyz2;
					ptE2 = stairs.m_RightRunData.PtRunBottomRight + xyz2;
					list4.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz3, ptE2, -xyz2));
					double bottomElevation2 = leftRunData.BottomElevation;
					BeamCurveInfo beamCurveInfo4 = new BeamCurveInfo(list4, bottomElevation2);
					beamCurveInfo4.m_Type = BeamType.BT_Bottom;
					beamCurveInfo4.m_nFloorNum = 0;
					stairs.m_listBeamCurve.Add(beamCurveInfo4);
				}
				if (bMid)
				{
					XYZ xyz2 = new XYZ(stairs.m_BeamData.BeamWidth / 2.0, 0.0, 0.0);
					List<CurveInfo> list5 = new List<CurveInfo>();
					xyz3 = ptLandTopLeft + xyz2;
					ptE2 = xyz3 - XYZ.BasisY * stairs.m_LandData.Width;
					list5.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz3, ptE2, null));
					xyz3 = ptLandTopRight - xyz2;
					ptE2 = xyz3 - XYZ.BasisY * stairs.m_LandData.Width;
					list5.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz3, ptE2, null));
					double bottomElevation2 = midRunData.BottomElevation;
					BeamCurveInfo beamCurveInfo5 = new BeamCurveInfo(list5, bottomElevation2);
					beamCurveInfo5.m_Type = BeamType.BT_Mid;
					beamCurveInfo5.m_nFloorNum = 1;
					stairs.m_listBeamCurve.Add(beamCurveInfo5);
				}
				if (bTop)
				{
					XYZ xyz2 = new XYZ(0.0, stairs.m_BeamData.BeamWidth / 2.0, 0.0);
					List<CurveInfo> list6 = new List<CurveInfo>();
					xyz3 = midRunData.PtRunBottomLeft - xyz2;
					ptE2 = midRunData.PtRunBottomRight - xyz2;
					list6.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, xyz3, ptE2, -xyz2));
					double bottomElevation2 = midRunData.BottomElevation + midRunData.RunHeight - midRunData.TreadHeight;
					BeamCurveInfo beamCurveInfo6 = new BeamCurveInfo(list6, bottomElevation2);
					beamCurveInfo6.m_Type = BeamType.BT_Top;
					beamCurveInfo6.m_nFloorNum = 2;
					stairs.m_listBeamCurve.Add(beamCurveInfo6);
				}
			}
		}

		private void DrawDoubleBranchAngleStairsLanding(ref List<CurveInfo> landingEdgeLoop, XYZ ptBaseLT, XYZ ptBaseRT, XYZ ptBaseRB, XYZ ptBaseLB)
		{
			landingEdgeLoop.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, ptBaseLT, ptBaseRT, null));
			landingEdgeLoop.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, ptBaseRT, ptBaseRB, null));
			landingEdgeLoop.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, ptBaseRB, ptBaseLB, null));
			landingEdgeLoop.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, ptBaseLB, ptBaseLT, null));
		}

		private void DrawDoubleBranchAngleStairsNoteInfo(ref DoubleBranchAngleStairs stairs, XYZ ptBaseLBL, XYZ ptBaseLBM, XYZ ptLandLT)
		{
			LineRunData leftRunData = stairs.m_LeftRunData;
			LineRunData midRunData = stairs.m_MidRunData;
			double length = stairs.m_LandData.Length;
			double width = stairs.m_LandData.Width;
			XYZ xyz = ptBaseLBL - XYZ.BasisX * 2.0;
			XYZ xyz2 = xyz - XYZ.BasisY * leftRunData.RunWidth;
			base.DrawStairsNoteInfo(ref stairs.m_listOtherCurve, ref stairs.m_listText, xyz2, xyz, "边梯段宽", 0.8, 2.0, 5.0, 1, null);
			xyz2 = ptBaseLBM - XYZ.BasisY * 2.0;
			xyz = xyz2 + XYZ.BasisX * midRunData.RunWidth;
			base.DrawStairsNoteInfo(ref stairs.m_listOtherCurve, ref stairs.m_listText, xyz2, xyz, "中梯段宽", 0.8, 5.0, 2.0, 1, null);
			xyz2 = ptLandLT + XYZ.BasisY * 1.5;
			xyz = xyz2 + XYZ.BasisX * length;
			base.DrawStairsNoteInfo(ref stairs.m_listOtherCurve, ref stairs.m_listText, xyz2, xyz, "休息平台长度", 0.8, 8.0, 2.0, 1, null);
			xyz = ptLandLT + XYZ.BasisX * length - XYZ.BasisX * 1.5;
			xyz2 = xyz - XYZ.BasisY * width;
			base.DrawStairsNoteInfo(ref stairs.m_listOtherCurve, ref stairs.m_listText, xyz2, xyz, "休息平台宽度", 0.8, 2.0, 8.0, 1, null);
			xyz2 = ptBaseLBL + XYZ.BasisY * 1.5;
			xyz = xyz2 + XYZ.BasisX * stairs.m_LeftRunData.TreadDepth;
			base.DrawStairsNoteInfo(ref stairs.m_listOtherCurve, ref stairs.m_listText, xyz2, xyz, "踏步宽度", 0.8, 5.0, 2.0, 1, null);
		}
	}
}
